$('#contact').live("pagebeforeshow", function(event) {
	$('#contact_methods').empty();
	doContact();
});
$('#home').live("pagebeforeshow", function(event) {
	localStorage["contact"] = null;
});

function doContact(){
	var person = JSON.parse(localStorage["contact"]);
	if(person.mail != null) {
		var url = 'mailto:' + person.mail;
		li = $('<li><a href='+url+'><h2>Mail</h2></a></li>');
		li.find('a').click(onMail);
		$('#contact_methods').append(li);
	}
	if(person.twitterName != null) {
		li = $('<li><a href="#make_tweet" data-rel="dialog" data-transition="pop"><h2>Tweet</h2></a></li>');
		$('#contact_methods').append(li);
	}
	li = $('<li><a href="#plan_afspraak"><h2>Maak Afspraak</h2></a></li>');
	$('#contact_methods').append(li);
	
	$('#contact_methods').listview("refresh");
}

function onMail() {

}

function postNewTweet(){
	var t = { "vakId":course.vakId, "subject":onderwerp, "text":new_question_text.value};
	console.log(JSON.stringify( t));
	var t1 = JSON.stringify(t);
	
	$.ajax( { 
		url: '/api/tweet/add',
		type: 'POST',	// Now we wait till we get response.
		data: t1,
		dataType:"json",
		contentType: 'application/json',
		success: function(data) { 	// ad the last 2 tweets to the page
				console.log("Gelukt!!");
		},
		error: function(data) { 	// ad the last 2 tweets to the page
			console.log("NIET Gelukt!!");
			console.log(data);
		}
		}
	);
	$.mobile.changePage('#course');
}